package cn.gson.crm.controller.emplo;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import cn.gson.crm.controller.BaseServlet;
import cn.gson.crm.model.dao.DeptDao;
import cn.gson.crm.model.dao.EmploDao;
import cn.gson.crm.model.entity.Dept;
import cn.gson.crm.model.entity.Employee;

/**
 * 员工类型
 */
@WebServlet("/employee")
public class EmployeeServlet extends BaseServlet {
	private static final long serialVersionUID = 1L;
    private EmploDao emploDao = new EmploDao();
    private DeptDao deptDao = new DeptDao();

	/**
	 * 进行显示员工
	 */
	@Override
	protected void get(HttpServletRequest request, HttpServletResponse response) throws Exception {
		
		String p= request.getParameter("page");
		String userName = request.getParameter("userName");
		String dept = request.getParameter("dept");
		
		if(p == null || p.isEmpty()){
			p = "1";
		}
		Integer page = Integer.parseInt(p);
		List<Employee> emploList = emploDao.getPageEmploByStatus("正常", page, userName, dept);
		
		//获取总页数
		int totalPage = emploDao.getTotalPage("正常", userName, dept);
		//获得部门
		List<Dept> deptList = deptDao.getDeptList(1);
		
		request.setAttribute("deptList", deptList);
	
		System.out.println(noPageQueryString(request));
		request.setAttribute("queryString", noPageQueryString(request));
		request.setAttribute("emploList", emploList);
		request.setAttribute("totalPage", totalPage);
		request.setAttribute("page", page);
		getServletPathAndForward(request,"employee/employee.jsp");
//		forward("employee/employee.jsp");
	}	
	/**
	 * 完成员工操作
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		doGet(request, response);
	}

}
